package com.ethereal.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

@WebServlet("/photo")
public class PhotoOutput extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        FileInputStream is = new FileInputStream("D:\\Pictures\\wallpaper\\ranni.jpg");
        byte[] bytes = new byte[1024];
        ServletOutputStream sos = resp.getOutputStream();
        int len;
        while ((len = is.read(bytes)) != -1){
            sos.write(bytes, 0, len);
        }
        is.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
